"""
    Created By Khun on 2020/4/8
"""

__author__ = 'Khun'

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired, Length

from app.models import User


class LoginForm(FlaskForm):
    """ 登录表单 """
    username = StringField('用户名', validators=[DataRequired(message='请输入用户名'), Length(3, 32, message='用户名不规范')])
    password = PasswordField('密码', validators=[DataRequired(message='请输入密码'), Length(5, 20, message='密码长度至少需要在6到20个字符之间')])

    # def validate_username(self, field):
    #     """ 验证用户名是否唯一 """
    #     if User.query.filter_by(username=field.data):
    #         raise ValidationError('用户名已被注册')
